package com.hqyj.ctxp.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hqyj.ctxp.mapper.UserInfoMapper;
import com.hqyj.ctxp.mapper.UserMapper;
import com.hqyj.ctxp.pojo.UserInfo;
import com.hqyj.ctxp.service.UserInfoService;
import com.hqyj.ctxp.utils.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    //展示个人信息
//    @Override
//    public ResultInfo selectUserInfo(String userName) {
//        UserInfo userInfo = userInfoMapper.selectUserInfo(userName);
//        return new ResultInfo(200,"用户个人信息查询成功",userInfo);
//    }


    @Override
    public ResultInfo selectUserById(Integer userNo) {
        UserInfo userInfo = userInfoMapper.selectUserById(userNo);
        return new ResultInfo(200,"用户个人信息查询成功",userInfo);
    }


    //修改个人信息
    @Override
    public ResultInfo updateUserInfo(UserInfo userInfo) {
        UpdateWrapper<UserInfo> wrapper = new UpdateWrapper<UserInfo>().eq("user_name", userInfo.getUserName())
                .set("user_phone", userInfo.getUserPhone())
                .set("user_image", userInfo.getUserImage())
                .set("user_age", userInfo.getUserAge())
                .set("user_gender", userInfo.getUserGender());
        int num = userInfoMapper.update(null, wrapper);
        if(num>0){
            return new ResultInfo(200,"修改成功",num);
        }
        return new ResultInfo(500,"修改失败");
    }
}
